package de.traveltainment.concept.envers.database;

import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Created by borlis on 13.06.2014.
 */
public class JdbcPropertiesReader {

    private static Logger logger = Logger.getLogger(JdbcPropertiesReader.class.getName());


    public static JdbcProperties getJdbcProperties() {
        InputStream input = null;
        try {

            input = JdbcPropertiesReader.class.getClassLoader().getResourceAsStream("jdbc.properties");
            // load a properties file
            JdbcProperties jdbcProperties = new JdbcProperties();
            jdbcProperties.getProperties().load(input);
            return jdbcProperties;

        } catch (IOException ex) {
            logger.log(Level.SEVERE, "Cannot read db configuration", ex);
            throw new RuntimeException(ex);
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    logger.log(Level.SEVERE, "Cannot close db configuration", e);
                }
            }
        }

    }
}
